package com.example.vp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.domain.R;
import com.common.holder.UserHolder;
import com.example.api.client.VideoClient;
import com.example.vp.domian.enetity.Collect;
import com.example.vp.domian.enetity.Subscribe;
import com.example.vp.domian.enetity.User;
import com.example.vp.domian.vo.UserVO;
import com.example.vp.mapper.AttentionMapper;
import com.example.vp.mapper.UserMapper;
import com.example.vp.service.AttentionService;
import com.example.vp.service.CollectService;
import com.example.vp.service.SubscribeService;
import com.example.vp.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Collection;
import java.util.List;

@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {
    @Autowired
    private SubscribeService subscribeService;
    @Autowired
    private AttentionService attentionService;
    @Autowired
    private VideoClient videoClient;
    
    @Override
    public UserVO getUserById(Long userId) {
        User user = getById(userId);
        if(ObjectUtils.isEmpty(user)){
            return new UserVO();
        }
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user,userVO);
        //查询粉丝数 #TODO
        //查询关注数量 #TODO
        return userVO;
    }



    @Override
    public void attentionUser(Long id) {
        long userId = UserHolder.getUserId();
        attentionService.attentionUser(userId,id);
        
    }

    @Override
    public List<User> getFans(Long id) {
        return null;
    }

    @Override
    public UserVO getUser() {
        Long userId = UserHolder.getUserId();
        //获取用户信息
        User user = getById(userId);
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user,userVO);
        
        //获取粉丝数
        userVO.setFans(attentionService.getfansNumByUserId(userId));
        //获取关注数
        userVO.setFollow(attentionService.getattentionNum(userId));
        //获取获赞数
        R subscribeNum = videoClient.getlikeNum(userId);
        Integer data = (Integer) subscribeNum.getData();
        Long likes = Long.parseLong(data.toString());
        userVO.setLike(likes);
        return userVO;
    }

    @Override
    public Collection<Long> getAttentionVideo(Long id) {
        Long userId = UserHolder.getUserId();
        return attentionService.getAttentionByUserId(id);
    }


}
